package ttsolver.variables;

import ttsolver.input.Node;
import ttsolver.input.Train;

public class Xdepart extends DefaultVariable {

	private Train train;

	public Xdepart() {
		super(VariableType.XDEPART);
	}
	
	public Xdepart(Train train) {
		super(VariableType.X);
		this.train = train;
	}

	public Train getTrain() {
		return train;
	}

	public void setTrain(Train train) {
		this.train = train;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((train == null) ? 0 : train.getId().intValue());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		Xdepart other = (Xdepart) obj;

		if (train == null) {
			if (other.train != null)
				return false;
		} else if (!train.equals(other.train)) {
			return false;
		}

		return true;
	}

	@Override
	public int compareTo(Object obj) {
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;

		Xdepart other = (Xdepart) obj;

		if (this == other)
			return EQUAL;

		if (this.train != null && other.train != null) {
			if (this.train.getId() < other.train.getId())
				return BEFORE;
			if (this.train.getId() > other.train.getId())
				return AFTER;
		}

		return EQUAL;
	}

	@Override
	public String toString() {
		if (!printVar)
			return "";

		String s = (train != null) ? String.valueOf(train.getId()) : "";
		return "Xdepart_(" + s + ")";
	}

}
